package com.cuit.zuke.data.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.cuit.zuke.data.mapper.DictMapper;
import com.cuit.zuke.data.model.entity.Dict;
import com.cuit.zuke.data.model.vo.DictEeVo;
import org.springframework.beans.BeanUtils;

public class DictListener extends AnalysisEventListener<DictEeVo> {

    private DictMapper dictMapper;

    public DictListener(DictMapper dictMapper) {
        this.dictMapper = dictMapper;
    }

    /**
     * Dict处理数据时进行处理
     * @param dictEeVo dictEeVo
     * @param analysisContext 默认参数
     * @return void
     */
    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {
        // DictEeVo -> Dict
        //调用方法添加到数据库
        Dict dict = new Dict();
        // spring自带工具类，将参数1中内容copy到参数2
        BeanUtils.copyProperties(dictEeVo,dict);
        dictMapper.insert(dict);
    }

    /**
     * Dict处理完数据后的处理
     * @param analysisContext 默认参数
     * @return void
     */
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
